# -*- coding: utf-8 -*-
__author__ = 'Administrator'
import requests
import re
url = "https://play.google.com/store/apps/details?id=com.tiens.pocket"

s = requests.get(url).text

s_par = '<div class="IQ1z0d"><span class="htlgb">(.*?)</span></div>'

# new = '''<h2 class="Rm6Gwb">新功能</h2>
# <span jsslot>gfidgj.fk'''
re_res = re.findall(s_par, s)
new_description_list = re.findall('<span jsslot>(.*?)</span>', s)
new_description = new_description_list[-1].replace('<br>', " ")
#
# print(new_description)
# print(re_res)
update_date = re_res[0]
app_size = re_res[1]
download_count = re_res[2]
app_version = re_res[3]
android_ver_need = re_res[4]


def record():
    with open('version.txt', 'a+') as f:
        f.write('版本:V' + app_version + "-" + 'Updatetime:' + update_date + "-" + "文件大小:" + app_size + "- 支持安卓版本：" + android_ver_need + '- 更新内容：'+ new_description + '\n')
        f.close()


import os

def verify_info():
    fsize = os.path.getsize('version.txt')
    with open('version.txt') as f:
     # print(fsize)   # 文件大小
       if fsize == 0:
           record()
       else:
           s = f.readlines()[-1].split('-')
           old_ver = s[0][4:]
           old_update = s[1][11:]

           if old_ver == app_version and old_update == update_date:
               print("无更新")
           else:
               record()


if os.path.exists("version.txt"):
    verify_info()

else:
    file = open("version.txt",'w')
    verify_info()

